package com.sairui.xiaoruilibdemo;

import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.view.View;

import com.sairui.xiaoruilib.XiaoRuiFragment;

/**
 * Created by sunqiyong on 2018/7/2.
 */

public class MyViewPagerAdapter extends FragmentStatePagerAdapter {
    private HomeFragment fragment1;
    private DemoFragment fragment2;
    private XiaoRuiFragment mXiaoRuiFragment;
    private DemoFragment fragment3;
    private DemoFragment fragment4;

    public MyViewPagerAdapter(FragmentManager fm) {
        super(fm);
    }


    @Override
    public int getCount() {
        return 5;
    }

    @Override
    public Fragment getItem(int position) {
        switch (position) {
            case 0:
                if (null == fragment1) {
                    fragment1 = HomeFragment.getInstance();
                }
                return fragment1;
            case 1:
                if (null == fragment2) {
                    fragment2 = DemoFragment.getInstance("fragment2");
                }
                return fragment2;
            case 2:
                if (null == mXiaoRuiFragment) {
                    mXiaoRuiFragment = XiaoRuiFragment.getInstance();
                }
                return mXiaoRuiFragment;

            case 3:
                if (null == fragment3) {
                    fragment3 = DemoFragment.getInstance("fragment3");
                }
                return fragment3;
            case 4:
                if (null == fragment4) {
                    fragment4 = DemoFragment.getInstance("fragment4");
                }
                return fragment4;
            default:
                return null;
        }
    }
}
